package requests

import (
	"github.com/gin-gonic/gin"
	"github.com/thedevsaddam/govalidator"
)

// CreateArticleRequest 创建请求参数
type CreateArticleRequest struct {
	Title   string `json:"title" valid:"title"`
	Desc    string `json:"desc" valid:"desc"`
	Content string `json:"content,omitempty" valid:"content"`
}

func CreateArticle(data interface{}, c *gin.Context) map[string][]string {
	// 自定义验证规则
	rules := govalidator.MapData{
		"title":   []string{"required"},
		"desc":    []string{"required"},
		"content": []string{"required"},
	}

	// 自定义验证出错时的提示
	messages := govalidator.MapData{
		"title": []string{
			"required:标题为必填项",
		},
		"desc": []string{
			"required:文章简介为必填项",
		},
		"content": []string{
			"required:内容为必填项",
		},
	}

	return validate(data, rules, messages)
}
